<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        text-align: center;
        overflow-x: hidden;

        background-color: #d3cfcf;
        background-image: linear-gradient(
            90deg,
            transparent 79px,
            #f72e13 79px,
            #a8aaa8 81px,
            transparent 81px
          ),
          linear-gradient(#a29e9e 0.1em, transparent 0.1em);
        background-size: 100% 1.2em;
      }

      .box {
        color: aliceblue;
        width: 300px;
        height: 200px;
        line-height: 200px;
        margin: 10px auto;
        border-radius: 20px;
        box-shadow: 0 0 20px rgb(12, 1, 1);
        transform: translateX(400%);
        transition: transform 0.8s ease;

        background: radial-gradient(black 15%, transparent 16%) 0 0,
          radial-gradient(black 15%, transparent 16%) 8px 8px,
          radial-gradient(rgba(255, 255, 255, 0.1) 15%, transparent 20%) 0 1px,
          radial-gradient(rgba(255, 255, 255, 0.1) 15%, transparent 20%) 8px 9px;
        background-color: #282828;
        background-size: 16px 16px;
      }
      .box:nth-of-type(even) {
        transform: translateX(-400%);
      }
      .box.show {
        transform: translateX(0);
      }
    </style>
  </head>
  <body>
    <h1>滚动查看</h1>
    <div class="box active">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <div class="box">
      <h2>Context</h2>
    </div>
    <script>
      //getBoundingClientRect
      let boxEle = document.querySelectorAll('.box');

      window.addEventListener('scroll', checkBoxes); //监听
      checkBoxes();
      function checkBoxes() {
        boxEle.forEach((box) => {
          let triggerHeight = (window.innerHeight * 3) / 4;
          let boxTop = box.getBoundingClientRect().top; //获取当前盒子距离窗口顶部高度
          if (boxTop < triggerHeight) {
            box.classList.add('show');
          } else {
            box.classList.remove('show');
          }
        });
      }
    </script>
  </body>
</html>
